
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>如何优化 Nginx 的性能？有哪些常见的优化策略？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>如何优化 Nginx 的性能？有哪些常见的优化策略？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在Nginx中，`worker_processes`指令的最佳设置建议是什么？为什么这样设置可以提高性能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">建议将 `worker_processes` 设置为与服务器CPU核心数相等的值。这样配置可以使 Nginx 并行处理多个请求，从而提高吞吐量。</div>
          </div>
          <div class="card-source">来源: 1.1. 调整工作进程数</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">Nginx的`worker_connections`指令的作用是什么？调整这个值时需要考虑什么服务器资源？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`worker_connections`指令用于增加每个工作进程能够处理的最大并发连接数。调整这个值时需要考虑服务器的资源，特别是内存。</div>
          </div>
          <div class="card-source">来源: 1.2. 调整工作连接数</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">启用Nginx的`proxy_cache`缓存机制对后端服务器有什么好处？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">使用 `proxy_cache` 缓存可以减少对后端服务器的请求，从而降低其负载，并能更快地响应客户端，提高响应速度。</div>
          </div>
          <div class="card-source">来源: 1.3. 启用缓存</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">为了高效地传输静态文件，Nginx提供了哪两个关键指令？它们各自的作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">为了高效传输静态文件，可以使用 `sendfile` 和 `tcp_nopush` 指令。`sendfile` 可以提高静态文件的传输效率，而 `tcp_nopush` 则可以优化TCP数据包的传输。</div>
          </div>
          <div class="card-source">来源: 2.2. 使用高效的文件传输</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在处理静态文件时，使用`expires`指令能带来什么优化效果？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`expires`指令用于设置静态文件的过期时间，这可以减少客户端对同一文件的重复请求频率，从而降低服务器负载并加快页面加载速度。</div>
          </div>
          <div class="card-source">来源: 2.1. 启用静态文件缓存</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在优化反向代理时，`limit_req`指令的主要目的是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`limit_req`指令的主要目的是限制来自客户端的请求速率，这可以防止某些客户端发送过多请求，从而保护服务器资源不被耗尽。</div>
          </div>
          <div class="card-source">来源: 3.2. 限制请求速率</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">文档中提到了哪三种Nginx支持的负载均衡算法？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到的三种负载均衡算法是：`round-robin`（轮询，默认算法）、`least_conn`（最少连接）和 `ip_hash`（IP哈希）。</div>
          </div>
          <div class="card-source">来源: 4.1. 选择合适的负载均衡算法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">如何通过Nginx的配置来减少数据传输量并提高传输效率？请说明具体指令。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以通过启用Gzip压缩来减少数据传输量。具体指令是 `gzip on;`，并可以通过 `gzip_types` 指令来指定需要压缩的内容类型。</div>
          </div>
          <div class="card-source">来源: 1.4. 使用压缩</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">文档中提到了哪种Nginx自带的监控模块，以及如何启用它？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到了Nginx自带的`status`模块。通过在`server`配置块的某个`location`中添加 `stub_status on;` 指令即可启用它。</div>
          </div>
          <div class="card-source">来源: 5.1. 使用监控工具</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
